﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefCollectTask" :model="stateCollectTask.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_TaskName_FormItem" prop="Entity.TaskName" :label="$t('message.autotrans._Model_CollectTask_TaskName')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_CollectTask_TaskName')}), trigger: 'blur' }]" >
            <el-input v-model="stateCollectTask.vmModel.Entity.TaskName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_TargetDeviceType_FormItem" prop="Entity.TargetDeviceType" :label="$t('message.autotrans._Model_CollectTask_TargetDeviceType')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_CollectTask_TargetDeviceType')}), trigger: 'blur' }]" >
            <el-select v-model="stateCollectTask.vmModel.Entity.TargetDeviceType" clearable>
               <el-option key="ElectricMeter" value="ElectricMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_ElectricMeter')"></el-option>
               <el-option key="PressureMeter" value="PressureMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_PressureMeter')"></el-option>
               <el-option key="FlowMeter" value="FlowMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_FlowMeter')"></el-option>
               <el-option key="ProtectiveGasMeter" value="ProtectiveGasMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_ProtectiveGasMeter')"></el-option>
               <el-option key="GasMeter" value="GasMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_GasMeter')"></el-option>
               <el-option key="WaterMeter" value="WaterMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_WaterMeter')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_DeviceId_FormItem" prop="Entity.DeviceId" :label="$t('message.autotrans._Model_CollectTask_Device')">
            <el-select v-model="stateCollectTask.vmModel.Entity.DeviceId" clearable>
               <el-option v-for="item in stateCollectTask.AllDevices" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_IntervalMinutes_FormItem" prop="Entity.IntervalMinutes" :label="$t('message.autotrans._Model_CollectTask_IntervalMinutes')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_CollectTask_IntervalMinutes')}), trigger: 'blur' }]" >
            <el-input v-model="stateCollectTask.vmModel.Entity.IntervalMinutes" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_StartTime_FormItem" prop="Entity.StartTime" :label="$t('message.autotrans._Model_CollectTask_StartTime')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_CollectTask_StartTime')}), trigger: 'blur' }]" >
            <el-date-picker v-model="stateCollectTask.vmModel.Entity.StartTime" type='date' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_EndTime_FormItem" prop="Entity.EndTime" :label="$t('message.autotrans._Model_CollectTask_EndTime')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_CollectTask_EndTime')}), trigger: 'blur' }]" >
            <el-date-picker v-model="stateCollectTask.vmModel.Entity.EndTime" type='date' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Status_FormItem" prop="Entity.Status" :label="$t('message.autotrans._Model_CollectTask_Status')">
            <el-select v-model="stateCollectTask.vmModel.Entity.Status" clearable>
               <el-option key="Enabled" value="Enabled" :label="$t('message.autotrans._Enum_TaskStatusEnum_Enabled')"></el-option>
               <el-option key="Paused" value="Paused" :label="$t('message.autotrans._Enum_TaskStatusEnum_Paused')"></el-option>
               <el-option key="Completed" value="Completed" :label="$t('message.autotrans._Enum_TaskStatusEnum_Completed')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onSubmitCollectTask"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseCollectTask"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageIoTManagementCollectTaskEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { collecttaskApi } from '/@/api/iotmanagement/collecttask';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefCollectTask = ref();
const stateCollectTask = reactive({
    vmModel: {
	  Entity:{
        TaskName: '',
        TargetDeviceType: undefined,
        DeviceId: null,
        IntervalMinutes: null,
        StartTime: undefined,
        EndTime: undefined,
        Status: undefined,
        ID:null,
      },

	},
    
    AllDevices: [] as any[],
});

// 取消
const onCloseCollectTask = () => {
    closeDialog();
};

// 提交
const onSubmitCollectTask = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefCollectTask.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            collecttaskApi().edit(stateCollectTask.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/IoTManagement/CollectTask/GetMeterDevices',[],false).then(x=>{stateCollectTask.AllDevices = x});
    if (ci.attrs["wtmdata"]) {
		stateCollectTask.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateCollectTask.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	collecttaskApi().get(stateCollectTask.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateCollectTask.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

